var AV = require('leanengine');
var async = require('async');

//商品收藏的模型信息
var Balance = AV.Object.extend("AmountFlow");
var Product = AV.Object.extend("Product");
module.exports = {

    //获取用户余额流水
    getBalance:function(uid){
        if(uid) {
            var promise = new AV.Promise();
            async.waterfall([
                function (callback) {
                    //根据uid和pid获取该对象
                    query = new AV.Query(Balance);
                    query.equalTo('userid', uid);
                    query.descending('createdAt');
                    query.find().then(function (res) {
                        callback(null, res);
                    });
                }
            ], function (err, result) {
                if (err) {
                    promise.reject(err);
                } else {
                    promise.resolve(result);
                }
            });
            return promise;
        }else{
            return new AV.Promise.error({code:751});
        }
    }
};


